package com.example.demo.controller;

import com.example.demo.entity.Emp;
import com.example.demo.entity.EmpLoginInfo;
import com.example.demo.entity.Result;
import com.example.demo.exception.CustomException;
import com.example.demo.service.EmpService;
import com.example.demo.service.Impl.EmpServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {
    @Autowired
    private EmpServiceImpl empService;

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        log.info("员工来登录啦 参数:{}",emp);
        EmpLoginInfo empLoginInfo = empService.login(emp);
        if (empLoginInfo == null){
            throw new CustomException(Result.error("用户名或密码错误"));
        }else {
            return Result.success(empLoginInfo);
        }
    }
}
